<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>mbrtowc</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX &reg; Specification, Version 2<br>
Copyright &copy; 1997 The Open Group

</font></center><hr size=2 noshade>
<h4><a name = "tag_000_007_529">&nbsp;</a>NAME</h4><blockquote>
mbrtowc - convert a character to a wide-character code (restartable)
</blockquote><h4><a name = "tag_000_007_530">&nbsp;</a>SYNOPSIS</h4><blockquote>
<pre><code>

#include &lt;<a href="wchar.h.html">wchar.h</a>&gt;

size_t mbrtowc(wchar_t *<i>pwc</i>, const char *<i>s</i>, size_t <i>n</i>, mbstate_t *<i>ps</i>);
</code>
</pre>
</blockquote><h4><a name = "tag_000_007_531">&nbsp;</a>DESCRIPTION</h4><blockquote>
If
<i>s</i>
is a null pointer, the
<i>mbrtowc()</i>
function is equivalent to the call:
<pre>
<code>
mbrtowc(NULL, &quot;&quot;, 1, ps)
</code>
</pre>
<p>
In this case, the values of the arguments
<i>pwc</i>
and
<i>n</i>
are ignored.
<p>
If
<i>s</i>
is not a null pointer, the
<i>mbrtowc()</i>
function inspects at most
<i>n</i>
bytes beginning at the byte pointed to by 
<i>s</i>
to determine the number of bytes needed to complete the next 
character (including any shift sequences).  If the function determines
that the next character is completed, it determines the
value of the corresponding wide-character and then, if
<i>pwc</i>
is not a null pointer, stores that value in the object pointed to by
<i>pwc</i>.
If the corresponding wide-character is the null wide-character, the
resulting state described is the initial conversion state.
<p>
If
<i>ps</i>
is a null pointer, the
<i>mbrtowc()</i>
function uses its own internal
<b>mbstate_t</b>
object, which is initialised at program startup to the initial
conversion state.  
Otherwise, the 
<b>mbstate_t</b>
object pointed to by
<i>ps</i>
is used to completely describe the current conversion state of the
associated character sequence.
The implementation will behave as if no function defined in this
specification calls
<i>mbrtowc()</i>.
<p>
The behaviour of this function is affected by the LC_CTYPE category of
the current locale.  
</blockquote><h4><a name = "tag_000_007_532">&nbsp;</a>RETURN VALUE</h4><blockquote>
The
<i>mbrtowc()</i>
function returns the first of the following that applies:
<dl compact>

<dt>0<dd>If the next
<i>n</i>
or fewer bytes complete the character that corresponds to
the null wide-character (which is the value stored).

<dt><i>positive</i><dd>If the next
<i>n</i>
or fewer bytes complete a valid character (which is the
value stored); the value
returned is the number of bytes that complete the character.

<dt><b>(size_t)-2</b><dd>If the next
<i>n</i>
bytes contribute to an incomplete but potentially valid 
character, and all
<i>n</i>
bytes have been processed (no value is stored).  
When
<i>n</i>
has at least the value of the MB_CUR_MAX macro, this case can only
occur if 
<i>s</i>
points at a sequence of redundant shift sequences (for implementations
with state-dependent encodings).

<dt><b>(size_t)-1</b><dd>If an encoding error occurs, in which case the next
<i>n</i>
or fewer bytes do not contribute to a complete and valid 
character (no value is stored).  In this case, EILSEQ is stored in
<i>errno</i>
and the conversion state is undefined.

</dl>
</blockquote><h4><a name = "tag_000_007_533">&nbsp;</a>ERRORS</h4><blockquote>
The
<i>mbrtowc()</i>
function may fail if:
<dl compact>

<dt>[EINVAL]<dd>
<i>ps</i>
points to an object that contains an invalid conversion state.

<dt>[EILSEQ]<dd>
Invalid character sequence is detected.

</dl>
</blockquote><h4><a name = "tag_000_007_534">&nbsp;</a>EXAMPLES</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_535">&nbsp;</a>APPLICATION USAGE</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_536">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>
None.
</blockquote><h4><a name = "tag_000_007_537">&nbsp;</a>SEE ALSO</h4><blockquote>
<i><a href="mbsinit.html">mbsinit()</a></i>,
<i><a href="wchar.h.html">&lt;wchar.h&gt;</a></i>.
<br>
</blockquote><h4>DERIVATION</h4><blockquote>
Derived from the ISO/IEC 9899:1990/Amendment 1:1995 (E).
</blockquote><hr size=2 noshade>
<center><font size=2>
UNIX &reg; is a registered Trademark of The Open Group.<br>
Copyright &copy; 1997 The Open Group
<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]

</font></center><hr size=2 noshade>
</body></html>

